<?php

namespace App\Http\Controllers\Auction;

use App\Library\Mall\AuctionTrait;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class AuctionController extends Controller
{
    use AuctionTrait;

    public function buynow()
    {
        $itemid   = $this->request->input('itemid');
        $quantity = $this->request->input('quantity');
        $pay_type = $this->request->input('pay_type');
        $shipping_type = $this->request->input('shipping_type');

        $this->assign(compact('itemid', 'quantity', 'pay_type', 'shipping_type'));

        if ($itemid && $quantity) {
            $item = Item::find($itemid);
            if ($quantity > $item['stock']){
                return $this->showError(trans('mall.stock_no_enough'));
            }

            $total_fee = $item->price * $quantity;

            $shop = $item->shop;
            $this->assign(compact('item', 'shop', 'total_fee'));

            return $this->view('buy.buynow');
        } else{
            return $this->showError('can_not_buy');
        }
    }
}
